package com.sanyang.lawyer.service.Case;

import com.sanyang.lawyer.entity.Case_audit;
import com.sanyang.lawyer.entity.Case_client;
import com.sanyang.lawyer.entity.Case_law;
import com.sanyang.lawyer.entity.Case_message;
import com.sanyang.lawyer.mapper.Case.Case_lawMapper;
import com.sanyang.lawyer.service.client.Case_clientService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

@Service
public class Case_lawService {

    @Autowired
    private Case_lawMapper lawMapper;

    @Autowired
    private Case_clientService clientService;


    //查询全部 不含模糊查询
    public List<Case_law> listall(){
        return lawMapper.listall();
    }
    //查询全部包含模糊查询
    public List<Case_law> listalls(Map<String,String> map){
        return lawMapper.listalls(map);
    }

    //显示所有
    public List<Case_law> selectLikeList(Case_law case_law){
        return lawMapper.selectLikeList(case_law);
    }

    public Case_law queryByid(String caseid){
        return lawMapper.queryOne(caseid);
    }

    //利益冲突监测
    public List<Case_law> detection(Case_message case_message){
        return lawMapper.detection(case_message);
    }

    //查询最大的version
    public int getMaxKey(){
        return lawMapper.getMaxKey();
    }

    //添加一条案件
    public void insertOne(Case_law case_law){
        //添加案件
        lawMapper.insertOne(case_law);

        Case_client client = new Case_client();
        client.setClient(case_law.getClientId());
        client.setCaseid(case_law.getCaseId());
        client.setTypeid(1);
        client.setIdentity("委托人");

        Case_client oppositeId = new Case_client();
        oppositeId.setClient(case_law.getOppositeId());
        oppositeId.setCaseid(case_law.getCaseId());
        oppositeId.setTypeid(1);
        oppositeId.setIdentity("对方当事人");

        //添加案件和客户中间表的数据
        clientService.insertOne(client);
        clientService.insertOne(oppositeId);
    }


    //根据流程id查询出相关的案件信息
    public Case_law queryCaseByprocessid(String processid){
        return lawMapper.queryCaseByprocessid(processid);
    }


    //修改案件审核状态
    public void update_closestate(Case_law case_law){
        lawMapper.update_closestate(case_law);
    }

    public List<Case_law> casequery(Map<String,String> map){
        return lawMapper.casequery(map);
    }

    //根据案件id查询案号,委托人名称，代理费用，杂费
    public Case_law gatheringQuery(String caseid){
        return lawMapper.gatheringQuery(caseid);
    }

    //修改数据库中的数据  修改未付,实付.
    public String gathering(Case_law law){
        lawMapper.gathering(law);
        return "成功";
    }
    


    //费用减免修改 代理费 应付 和未付  减去 减免费用
    public void complateUpdte(Case_audit case_audit){
        lawMapper.complateUpdte(case_audit);
    }

    //3：根据审核id关联案件，将案件表数据修改 将案件的状态修改为已结案
    public void updateCase_status(String auditid) {
        String caseid = lawMapper.queryCaseidByProcessid(auditid);
        lawMapper.updateCase_status(caseid);
    }


    //案件修改
    public void Case_update(Case_law law){
        lawMapper.Case_update(law);
    }

    //查询出所有的已删除的案件
    public List<Case_law> selectCaseBystatus(Case_law case_law) {
        return lawMapper.selectCaseBystatus(case_law);
    }

    //根据案件id将案件表的状态修改为已删除
    public void deleteCase(String caseid) {
        lawMapper.deleteCase(caseid);
    }



    public List<Case_law> getlist(){
        return lawMapper.getlist();
    }

    

    public List<Case_law> backlog(){
        return  lawMapper.backlog();
    }
    public List<Case_law> backlogl(){
        return  lawMapper.backlog();
    }
    public List<Case_law> settle(){
        return  lawMapper.settle();
    }

    
    //收结案统计
    public List<Map<String,Object>> StatisticsList(Map map){
        return lawMapper.StatisticsList(map);
    }
    public Integer StatisticsListCount(Map map){return  lawMapper.StatisticsListCount(map);}
    //业务收费汇总
    public List<Map<String,Object>> businessCharge(Map map){
        return lawMapper.businessCharge(map);
    }
    public Integer businessChargeCount(Map map){return lawMapper.businessChargeCount(map);}
    //个人业务总计
    public List<Map<String,Object>> personalBusiness(Map map){return lawMapper.personalBusiness(map);}
    public Integer personalBusinessCount(Map map){return lawMapper.personalBusinessCount(map);}
    //法律顾问汇总
    public List<Map<String,Object>> legalCounsel(Map map){return  lawMapper.legalCounsel(map);}
    public Integer legalCounselCount(Map map){return lawMapper.legalCounselCount(map);}
}
